package services

import (
	"gitee.com/zhoulvvv/my_go_gateway/dao"
	"github.com/e421083458/golang_common/lib"
	"github.com/gin-gonic/gin"
	"github.com/pkg/errors"
	"gorm.io/gorm"
)

type AdminService struct {
	tx *gorm.DB
}

func NewAdminService() (*AdminService, error) {
	tx, err := lib.GetGormPool("default")
	if err != nil {
		return nil, errors.New("获取数据库连接池失败")
	}
	return &AdminService{
		tx: tx,
	}, nil
}

func (as *AdminService) GetUserInfoById(c *gin.Context, id int) (*dao.Admin, error) {
	admin := &dao.Admin{Id: id}
	return admin.Find(c, as.tx, admin)
}

func (as *AdminService) Update(c *gin.Context, admin *dao.Admin) error {
	return admin.Save(c, as.tx)
}
